package com.czp.ssm.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.czp.ssm.bean.Menu;
import com.czp.ssm.bean.Role;
import com.czp.ssm.bean.RoleExample;
import com.czp.ssm.bean.RoleMenu;
import com.czp.ssm.dao.MenuMapper;
import com.czp.ssm.dao.RoleMapper;
import com.czp.ssm.dao.RoleMenuMapper;
import com.czp.ssm.service.RoleService;
@Service
public class RoleServiceImpl implements RoleService {

	
	@Autowired
	private RoleMapper roleMapper;
	@Autowired
	private RoleMenuMapper roleMenuMapper;
	@Autowired
	private MenuMapper menuMapper;
	
	public List<Role> findAllRole() {
		RoleExample example = new RoleExample();
		List<Role> roles = roleMapper.selectByExample(example);
		for (int i = 0; i < roles.size(); i++) {
			Role role = roles.get(i);
			List<RoleMenu> roleMenus = roleMenuMapper.selectRoleMenuByRoleId(role.getRoleId());
			List<Menu> menus = new ArrayList<Menu>();
			for (int j = 0; j < roleMenus.size(); j++) {
				RoleMenu roleMenu = roleMenus.get(j);
				Menu menu = menuMapper.selectMenuByRoleId(roleMenu.getMenuId());
				menus.add(menu);
			}
			role.setMenus(menus);
		}
		return roles;
	}

}
